<%= render :partial => 'admin/shared/product_sub_menu' %>

<%= render :partial => 'admin/shared/product_tabs', :locals => {:current => "Variants"} %>

<table class="index">
	<tr>
		<th><%= t("options") %></th>
		<th><%= t("price") %></th>
	  <th><%= t("sku") %></th>
	  <% Variant.additional_fields.select{|f| f[:only].nil? || f[:only].include?(:variant) }.each do |field| %>
	    <th><%= field[:name].titleize %></th>
	  <% end %>
	  <th><%= t("on_hand") %></th>
		<th><%= t("action") %></th>
	</tr>
  <% @variants.each do |variant| %>
    <!-- you can skip variant with no options: that's just the default variant that all products have -->
    <% next if variant.option_values.empty? %>
    <tr <%= 'style="color:red;"' unless variant.deleted_at.nil? %>>
    	<td><%= variant_options variant %></td>
    	<td><%= variant.price %></td>
      <td><%= variant.sku %></td>
      <% Variant.additional_fields.select{|f| f[:only].nil? || f[:only].include?(:variant) }.each do |field| %>        
		    <td><%= variant[field[:name].gsub(" ", "_").downcase] %></td>
		  <% end %>
      <td><%= variant.on_hand %></td>
	    <td valign="top">
	      <%= link_to_edit(variant) if variant.deleted_at.nil? %>
	      &nbsp;
	      <%= link_to_delete(variant) if variant.deleted_at.nil? %>
	    </td>        
    </tr>
  <% end %>
  <% unless @product.variants? %>
    <tr><td colspan="5"><%= t("none") %>.</td></tr>
  <% end %>
</table>

<% if @product.options.empty? %>
  <p>
    <%= t("to_add_variants_you_must_first_define") %>  <%= link_to t("option_types"), selected_admin_product_option_types_url(@product) %>
  </p>
<% else %>
  <div id="variants"></div>
  <br/>
  <p id="new_var_link">
      <%= link_to_remote icon('add') + ' ' + t("new_variant"), 
                         {:url => new_admin_product_variant_url(@product), 
                         :method => :get,
                         :update => "variants",
                         :before => "Element.hide('new_var_link');Element.show('busy_indicator')", 
                         :complete => "Element.hide('busy_indicator')"}, :class => 'iconlink' %>
    </span>&nbsp;|&nbsp;<%= link_to @deleted.blank? ? t("show_deleted") : t("show_active"), admin_product_variants_url(@product, :deleted =>  @deleted.blank? ? "on" : "off") %>
  </p>
  <%= image_tag "spinner.gif", :plugin=>"spree", :style => "display:none", :id => 'busy_indicator' %>
<% end %>
